package fudan.se.project.repository.entity;

import fudan.se.project.domain.User;
import fudan.se.project.domain.conference.Conference;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author LBW
 */
@Repository
public interface UserRepository extends CrudRepository<User, Long> {

    User findByUsername(String username);

    List<User> findByRealname(String realname);

    User findByEmail(String email);

    @Query(value = "select " +
            "distinct user from User user " +
            "where  user.realname = :realname " +
            "and (:conference not in (select distinct pcMember.conference from user.pcMembers pcMember)) " +
            "and (:conference not in (select distinct chair.conference from user.chairs chair)) "
    )
    List<User> findUsersNotPcMemberInConference(String realname, Conference conference);
}
